package com.chongxinlaiguo.mapstruct.dto.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 渠道类型
 */
@AllArgsConstructor
@Getter
public enum ChannelEnum {

    UNION_PAY(1, "UnionPay", "银联商务", false,false),
    AIR_PORT_PAY(2, "AirPortPay", "长沙机场空港", true,false),
    ICBC_PAY(3, "IcbcPay", "工行支付", true,false),
    SQUARE(4, "Square", "美国Square", true,false),
    RAZORPAY(5, "RazorPay", "马来RazorPay", true,false),
    CHAGEE_WALLET(6, "ChageeWallet", "霸王茶姬钱包", true,false),
    CAPITAL_AIR_PORT_PAY(7,"CapitalAirPortPay", "首都机场",true,false),
    ANTOM(8, "Antom", "泰国蚂蚁支付2C2P", true,false),
    XENDIT(9, "Xendit", "印尼Xendit", true,false),
    ADYEN(10, "Adyen", "新加坡Adyen", true,true),
    RAZER(11, "Razer", "新加坡Razer", true,false),
    PAYOO(12, "Payoo", "越南Payoo", true,false),


    ;

    private Integer bChannelType; // b端的渠道标识  可能没有什么用
    private String channelCode; // c端的渠道编码
    private String channelName; // 渠道名称
    private boolean payMethodMsgSame; // 不同支付方式对应的报文相同；true-相同，false-不相同
    private boolean needAdvancePay; // 是否需要推进支付；true-需要，false-不需要


    public static ChannelEnum getChannelEnum(Integer bChannelType) {
        return Arrays.stream(ChannelEnum.values()).
                filter(item -> item.getBChannelType().equals(bChannelType)).findFirst().
                orElse(null);
    }

    private static Map<String, ChannelEnum> channelCodeMap;

    static {
        channelCodeMap = Arrays.stream(ChannelEnum.values()).collect(Collectors.toMap(ChannelEnum::getChannelCode, Function.identity(), (k1, k2) -> k2));
    }

    public static ChannelEnum getChannelEnum(String channelCode) {
        return channelCodeMap.get(channelCode);
    }
}
